from flask import Flask, render_template, request, Config

from apps.service.LoginService import LoginService
from apps.pojo.Entity import db

app = Flask(__name__)

#
app.config['SQLALCHEMY_DATABASE_URI'] = 'Mysql+pymysql://root:root@localhost:3306/flask'

#初始化数据库表
with app.app_context():
    db.init_app(app)
    db.drop_all()
    db.create_all()

@app.route('/')
def tologin():
  return render_template('login.html')

@app.route('/login',methods=['POST'])
def dologin():
    param=request.form
    username=param.get('username')
    password=param.get('password')
    user=LoginService.login(username,password)
    if user:
        return render_template('login.html',user=user)
    else:
        return render_template('index.html',msg="")


@app.route('/index')
def index():
    name='hello'
    return render_template('index.html',name=name)


if __name__ == '__main__':
    app.run()
